/*
 * DisplayManager.cpp
 *
 *  Created on: 29/lug/2011
 *      Author: marcolembo
 */

#include "DisplayManager.h"
#ifndef _WP_
#define _WP_
#include "WProgram.h"
#endif
namespace ml
{

    DisplayManager* DisplayManager::s_dm = 0;

    DisplayManager* DisplayManager::GetInstance(
                                            short _pinData,
                                            short _pinClock,
                                            short _pinEn)
    {
        if(!s_dm)
            s_dm = new DisplayManager(_pinData,
                                      _pinClock,
                                      _pinEn);
        return s_dm;

    }


    DisplayManager::DisplayManager(short _pinData,
                                   short _pinClock,
                                   short _pinEn)

    {
        m_lcd = new ShiftRegLCD(_pinData, _pinClock, _pinEn, 4);
        setCursor(0,0);
        printSplashScreen();


    }


    void DisplayManager::printSplashScreen() const
    {
        delay(15);
        m_lcd->noBlink();
        m_lcd->noCursor();

        m_lcd->clear();
        uint8_t M1[][8] =
        {

            {0x02, 0x03, 0x07, 0x07, 0x0D, 0x0C, 0x18, 0x18},
            {0x01, 0x03, 0x17, 0x1F, 0x1D, 0x19, 0x11, 0x01},
    //      {0x10, 0x11, 0x17, 0x1F, 0x1D, 0x11, 0x11, 0x11},
            {0x00, 0x01, 0x07, 0x0F, 0x0D, 0x01, 0x01, 0x01},

            {0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C},
            {0x11, 0x11, 0x19, 0x01, 0x07, 0x0F, 0x0F, 0x06},
            {0x01, 0x1B, 0x18, 0x0C, 0x04, 0x00, 0x00, 0x00},
    //      {0x11, 0x19, 0x01, 0x01, 0x07, 0x07, 0x00, 0x00},
            {0x01, 0x01, 0x01, 0x01, 0x07, 0x07, 0x00, 0x00},
            {0x1C, 0x1C, 0x1C, 0x1F, 0x1F, 0x1F, 0x00, 0x00}

        };

    //lcd.cursor();
    //lcd.blink();

        m_lcd->createChar(0, M1[0]);
        m_lcd->createChar(1, M1[1]);
        m_lcd->createChar(2, M1[2]);
        m_lcd->createChar(3, M1[3]);
        m_lcd->createChar(4, M1[4]);
        m_lcd->createChar(5, M1[5]);
        m_lcd->createChar(6, M1[6]);
        m_lcd->createChar(7, M1[7]);


        m_lcd->write(0);
        m_lcd->write(1);
        m_lcd->write(2);
        m_lcd->write(3);

        m_lcd->setCursor(0,1);
        m_lcd->write(4);
        m_lcd->write(5);
        m_lcd->write(6);
        m_lcd->write(7);

    //15
        m_lcd->setCursor(6,0);
        m_lcd->print("============");
        m_lcd->setCursor(6,1);
        m_lcd->print("M A R K ");
        m_lcd->write(2); m_lcd->write(3);
        m_lcd->setCursor(6,2);
        m_lcd->print("========");
        m_lcd->write(6); m_lcd->write(7);
        m_lcd->print("==");
        m_lcd->setCursor(6,3);
        m_lcd->print("^^^^^^^^^^^^");

    }

    DisplayManager::~DisplayManager()
    {
        delete m_lcd;
    }

}
